<%@page import="entities.Link"%>
<%@page import="entities.Category"%>
<%@page import="java.util.List"%>
<%@page import="helpers.UrlHelper"%>
<%@page import="java.util.ArrayList"%>
<%@page import="java.util.TreeMap"%>
<%
TreeMap check = (TreeMap) request.getAttribute("check");
List<Category> categories = (ArrayList<Category>) request.getAttribute("categories");
String success = (String) request.getAttribute("success");
Link link = (Link) request.getAttribute("link");
String form = (String) request.getAttribute("form");
%>

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<jsp:include page="/admin/layouts/header.jsp" />

<link rel="stylesheet" type="text/css" href="/admin/css/select2.css" />
<script type="text/javascript" src="/admin/js/custom/link_form.js"></script>
<script type='text/javascript' src="/admin/js/select2.min.js"></script>
<script type="text/javascript">
<!--
var status = "<%=link.getStatus()%>";
var type = "<%=link.getType() %>";
var category = "<%=link.getCategory() %>";
//-->
</script>
		
					<!-- Content Area -->
                	<div id="da-content-area">
                		<jsp:include page="/admin/elements/message_box.jsp" />
                        
                		<div class="grid_4">
                        	<div class="da-panel">
                            	<div class="da-panel-header">
                                	<span class="da-panel-title">
                                        <img src="/admin/images/icons/black/16/pencil.png" alt="" />
                                        Link Form
                                    </span>
                                    
                                </div>
                                <div class="da-panel-content">
                                	<form class="da-form" method="post">
                                    	<div class="da-form-inline">
                                            <div class="da-form-row type">
                                                <label>Link Type</label>
                                                <div class="da-form-item small">
                                                    <select name="type" class="<%=check.get("type") != null ? "error" : "" %>">
                                                    	<option value="free">Free Link</option>
														<option value="reciprocal">Free Link With Reciprocal</option>
														<option value="featured">Featured Link</option>
                                                    </select>
                                                    <% if (check.get("type") != null) { %>
                                                    <span class="errorMessage"><%=check.get("type") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-form-row">
                                                <label>Title <span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <input type="text" name="name" value="<%=link.getName() %>" class="<%=check.get("name") != null ? "error" : "" %>" />
                                                    <% if (check.get("name") != null) { %>
                                                    <span class="errorMessage"><%=check.get("name") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-form-row">
                                                <label>Url <span class="required">*</span></label>
                                                <div class="da-form-item small">
                                                    <input type="text" name="url" value="<%=link.getUrl() %>" class="<%=check.get("url") != null ? "error" : "" %>" />
                                                    <% if (check.get("url") != null) { %>
                                                    <span class="errorMessage"><%=check.get("url") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-form-row">
                                                <label>Description <span class="required">*</span></label>
                                                <div class="da-form-item default">
                                                    <textarea cols="auto" rows="auto" name="description" class="<%=check.get("description") != null ? "error" : "" %>" ><%=link.getDescription() %></textarea>
                                                    <% if (check.get("description") != null) { %>
                                                    <span class="errorMessage"><%=check.get("description") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-form-row">
                                                <label>Category</label>
                                                <div class="da-form-item small">
													<select name="category" class="select2">
														<%
														for (int i = 0; i < categories.size(); i++) {
														%>
														<option value="<%=categories.get(i).getId()%>">
															|<% for (int j = 2 ; j <= categories.get(i).getLevel(); j++) {%>&nbsp;&nbsp;|<% } %>___
															<%=categories.get(i).getName()%> (<%=categories.get(i).getLevel()%>)
														</option>
														<%
														}
														%>
													</select>
													<% if (check.get("category") != null) { %>
                                                    <span class="errorMessage"><%=check.get("category") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-form-row">
                                                <label>Status</label>
                                                <div class="da-form-item small">
                                                    <select name="status" class="<%=check.get("status") != null ? "error" : "" %>">
                                                    	<option value="0" label="Inactive">Inactive</option>
														<option value="1" label="Pending">Pending</option>
														<option value="2" label="Active">Active</option>
                                                    </select>
                                                    <% if (check.get("status") != null) { %>
                                                    <span class="errorMessage"><%=check.get("status") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-form-row reciprocal">
                                                <label>Reciprocal Link<span class="required">*</span></label>
                                                <div class="da-form-item default">
                                                	<input type="text" name="urlReciprocal" value="" class="text <%=check.get("urlReciprocal") != null ? "error" : "" %>">
                                               		<p>To validate the reciprocal link please include the following HTML code in the page at the URL specified above, before submiting this form:</p>
                                                    <textarea cols="auto" rows="auto" name="sourceReciprocal" ><%=link.getSourceReciprocal() %></textarea>
                                                    <% if (check.get("urlReciprocal") != null) { %>
                                                    <span class="errorMessage"><%=check.get("urlReciprocal") %></span>
                                                    <% } %>
                                                </div>
                                            </div>
                                            
                                            <div class="da-button-row">
                                            	<input type="submit" value="Submit" class="da-button blue left" />
	                                        	<input type="reset" value="Reset" class="da-button gray" />
	                                        </div>
                                        </div>
                                    </form>
                                </div>
                            </div>
                        </div>
                	</div>

<jsp:include page="/admin/layouts/footer.jsp" />